package org.example.infrastructure.repository.orm.database;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.domain.model.entity.url.UrlShortenerCorrelationGroup;
import org.example.domain.repository.UrlShortenerCorrelationGroupMapperRepository;
import org.example.infrastructure.persistence.orm.UrlShortenerCorrelationGroupMapper;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RequiredArgsConstructor
public class MybatisUrlShortenerCorrelationGroupMapperRepository implements UrlShortenerCorrelationGroupMapperRepository {
    private final UrlShortenerCorrelationGroupMapper urlShortenerCorrelationGroupMapper;

    @Override
    public void deleteByFullShortUrlAndGid(String fullShortUrl, String gid) {
        urlShortenerCorrelationGroupMapper.deleteByFullShortUrlAndGid(fullShortUrl, gid);
    }

    @Override
    public void insertUrlShortenerCorrelationGroup(String fullShortUrl, String gid) {
        urlShortenerCorrelationGroupMapper.insertUrlShortenerCorrelationGroup(fullShortUrl, gid);
    }

    @Override
    public UrlShortenerCorrelationGroup selectOneByFullShortUrl(String fullShortUrl) {
        LambdaQueryWrapper<UrlShortenerCorrelationGroup> queryWrapper = Wrappers.lambdaQuery(UrlShortenerCorrelationGroup.class)
                .eq(UrlShortenerCorrelationGroup::getFullShortUrl, fullShortUrl);
        return urlShortenerCorrelationGroupMapper.selectOne(queryWrapper);
    }
}
